﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _14_1_16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text += " " + DateTime.Now.ToString("yyyy-MM-dd");
        }

       

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btOpen_Click(object sender, EventArgs e)
        {
           DialogResult result = openFileDialog1.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                pictureBox1.ImageLocation = openFileDialog1.FileName;
            }
        }

        private void btDraw_Click(object sender, EventArgs e)
        {
            using(Graphics gr = pictureBox1.CreateGraphics())
            {
                gr.DrawLine(new Pen(Color.Black), 0, pictureBox1.Height/2, pictureBox1.Width, pictureBox1.Height / 2);
                gr.DrawLine(new Pen(Color.Black), pictureBox1.Width/2, 0, pictureBox1.Width/2, pictureBox1.Height);
                gr.DrawLine(new Pen(Color.Black), pictureBox1.Width/2, 0 , pictureBox1.Width/2 - 10, 10);
                gr.DrawLine(new Pen(Color.Black), pictureBox1.Width / 2, 0, pictureBox1.Width / 2 + 10, 10);
                gr.DrawLine(new Pen(Color.Black), pictureBox1.Width, pictureBox1.Height/2, pictureBox1.Width - 10, pictureBox1.Height/2 -10);
                gr.DrawLine(new Pen(Color.Black), pictureBox1.Width, pictureBox1.Height / 2, pictureBox1.Width - 10, pictureBox1.Height / 2 +10);
                Font drawFont = new Font("Arial", 16);
                SolidBrush drawBrush = new SolidBrush(Color.Black);
                gr.DrawString("x", drawFont, drawBrush, pictureBox1.Width - 20, pictureBox1.Height/2 + 20);
                gr.DrawString("y", drawFont, drawBrush, pictureBox1.Width/2 + 15, 10);
                gr.DrawString("function (y = x^2)", drawFont, drawBrush, 5, pictureBox1.Height - 30);
                // draw parabola by pix
                Pen blackPen = new Pen(Color.Black, 0.25F);
                for (float i = 0; i < 15; i = i + 0.005F)
                {
                    float j = i * i;
                    gr.DrawEllipse(blackPen, pictureBox1.Width / 2 + i, pictureBox1.Height / 2 - j, 0.025F, 0.025F);

                }
                // draw  scaled parabola scale = 10
                
                for (float i = 0; i < 150; i = i + 0.005F)
                {
                    int scale = 10;
                    float ii = i / scale;
                    float j = ii * ii;
                    gr.DrawEllipse(blackPen, pictureBox1.Width / 2 + i, pictureBox1.Height / 2 - j, 0.025F, 0.025F);

                }
                // make scale 
                Pen scalePen = new Pen(Color.Black, 1);
                // vertical
                for (int i = pictureBox1.Height/10; i < pictureBox1.Height; i += pictureBox1.Height/10)
                {
                    gr.DrawRectangle(scalePen, pictureBox1.Width / 2 - 2, i, 4, 1);
                }

                //horizontal
                for (int i = pictureBox1.Width / 10; i < pictureBox1.Width * 0.95; i += pictureBox1.Width / 10)
                {
                    gr.DrawRectangle(scalePen, i, pictureBox1.Height / 2 - 2, 1, 4);
                }                    

            }
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            DialogResult result = saveFileDialog1.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {

            }
            pictureBox1.Image.Save()
        }
    }
}
